// callback: cmd_table

void cmd_table(istringstream& ss) {
  string op;
  if(ss>>op) {
    if(op=="load") {
      string tfile,tname;
      if(ss>>tfile) {
        int pmark=tfile.find('@');
        if(pmark!=tfile.npos) {
          tname=tfile.substr(0,pmark);
          tfile.erase(0,pmark+1);
        } else tname="";
        
        double scl,c;
        if(!(ss>>scl>>c)) scl=c=1.0;
        TableReader* tab=new TableReader(tfile,tname,scl,c);
        table.push_back(tab);
        say("table loaded as "+tab->name);
      } else throw "file name required";
    }
    
    else if(op=="delete") {
      string tname;
      if(ss>>tname) {
        int tid=search_table(tname);
        if(tid<0) throw "table not found";
        delete table[tid];
        table.erase(table.begin()+tid);
      } else throw "table name required";
    }
    
    else if(op=="rename") {
      string oldname,newname;
      if(ss>>oldname>>newname) {
        int tid=search_table(oldname);
        if(tid<0) throw "table not found";
        table[tid]->name=newname;
      } else throw "sintax: rename oldname newname";
    }
    
    else throw "unknown operation";
    
  } else throw "load|delete";
}
